<%--
  Created by IntelliJ IDEA.
  User: abb
  Date: 2018-07-09
  Time: 18:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="/static/js/jquery-easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/js/jquery-easyui/themes/icon.css">
    <script type="text/javascript" src="/static/js/jquery-easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery-easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <title>Title</title>
    <script>

        $(function () {
            //表格
            var permission_datagrid = $("#permission_datagrid");

            //数据表格渲染
            permission_datagrid.datagrid({
                url:"/permission/list",
                fit:true,
                fitColumns:true,
                border:false,
                rownumbers:true,
                pagination:true,
                singleSelect:true,
                toolbar:'#permission_datagrid_toolbar',
                columns:[[
                    {field:'name',title:'权限名称',width:100},
                    {field:'resource',title:'权限表达式',width:100}
                ]]
            });

            //1.把方法绑定到一个对象上
            var cmdObj = {
                //加载权限
                reloadPermission:function () {

                    //给提确认框notice
                    $.messager.confirm("提示:","确定重新加载?",function (yes) {
                        if(yes){
                            //发送ajax请求,执行重新加载权限
                            $.post("/permission/reload",{},function (data) {
                                if(data.success){
                                    $.messager.alert("提示","操作成功","info",function () {
                                        //刷新页面
                                        permission_datagrid.datagrid("reload");
                                    })
                                }else{
                                    $.messager.alert("提示",data.msg,"error");
                                }
                            });
                        }
                    })
                }
            };

            //2.按钮的点击事件通过js来绑定
            $("a[data-cmd]").click(function () {
                var cmd = $(this).data("cmd");
                cmdObj[cmd]() ;
            });

        });

    </script>
</head>
<body>

<div id="permission_datagrid_toolbar">
    <a class="easyui-linkbutton" iconCls="icon-reload" plain="true" data-cmd="reloadPermission" >加载权限</a>
</div>

<%--表格--%>
<table id="permission_datagrid"></table>
</body>
</html>
